<template>
  <div class="singer_square">
    <div class="selectbox">
      <div class="areabox">
        <div class="title">地区：</div>
        <template v-for="(item, index) in area">
          <div
            :key="item.id"
            class="areaitem"
            :class="index == areaIndex ? 'active' : ''"
            @click="changeArea(index)"
          >
            {{ item.value }}
          </div>
        </template>
      </div>
      <div class="typebox">
        <div class="title">类型：</div>
        <template v-for="(item, index) in type">
          <div
            :key="item.id"
            class="typeitem"
            :class="index == typeIndex ? 'active' : ''"
            @click="changeType(index)"
          >
            {{ item.value }}
          </div>
        </template>
      </div>
      <div class="screening">
        <div class="title">筛选：</div>
        <div class="screening_item">
          <template v-for="(item, index) in letter">
            <span
              :key="index"
              class="typeitem"
              :class="index == letterIndex ? 'active' : ''"
              @click="changeLetter(index)"
            >
              {{ item }}
            </span>
          </template>
        </div>
      </div>
    </div>
    <div class="singerbox">
      <div
        class="singeritem"
        v-for="(item, index) in singerList"
        :key="index"
        @click="gotoSinger(item)"
      >
        <div class="singerimage">
          <img class="" :src="item.picUrl + '?param=200y200'" />
        </div>
        <div class="singername">{{ item.name }}</div>
      </div>
    </div>
    <div class="more" @click="more">
      查看更多
    </div>
  </div>
</template>

<script>
import request from "../../../../api/request"
export default {
  data() {
    return {
      // 请求歌手分类数据必传参数cat的值，每个数字第一位表示地区：1 为华语  2 为欧美   6 为日本   7 为韩国  4 为其他
      // 最后以为表示类型：1 为男歌手  2 为女歌手  3 为组合
      catList: [
        [1001, 1002, 1003],
        [2001, 2002, 2003],
        [6001, 6002, 6003],
        [7001, 7002, 7003],
        [4001, 4002, 4003],
      ],
      total: 0,
      areaIndex: 0,
      typeIndex: 0,
      letterIndex: 0,
      // area: ["全部", "华语", "欧美", "日本", "韩国", "其他"],
      // type: ["全部", "男歌手", "女歌手", "组合"],
      singerList: [],
      limit: 21,
      page: 1,
      // type:[],
      letter: ["热门"],
      type: [
        { id: -1, value: "全部" },
        { id: 1, value: "男歌手" },
        { id: 2, value: "女歌手" },
        { id: 3, value: "组合" },
      ],
      area: [
        { id: -1, value: "全部" },
        { id: 7, value: "华语" },
        { id: 96, value: "欧美" },
        { id: 8, value: "日本" },
        { id: 16, value: "韩国" },
        { id: 0, value: "其他" },
      ],
    }
  },
  created() {
    this.getSinger()
    this.getLetter()
  },
  methods: {
    async getSinger() {
      // console.log(
      //   this.type[this.typeIndex].id,
      //   this.area[this.areaIndex].id,
      //   this.letterIndex == 0 ? -1 : this.letter[this.letterIndex]
      // )
      this.singerList = []
      let res = await request({
        url: "/artist/list",
        data: {
          // cat: this.catList[this.areaIndex][this.typeIndex],
          type: this.type[this.typeIndex].id,
          area: this.area[this.areaIndex].id,
          initial: this.letterIndex == 0 ? -1 : this.letter[this.letterIndex],
          offset: (this.page - 1) * this.limit,
        },
        method: "get",
      })
      console.log(res)
      this.singerList.push(...res.artists)
    },
    changeArea(index) {
      this.areaIndex = index
      this.page = 1
      this.getSinger()
    },
    changeType(index) {
      this.typeIndex = index
      this.page = 1
      this.getSinger()
    },
    changeLetter(index) {
      this.letterIndex = index
      this.page = 1
      this.getSinger()
    },
    async more() {
      this.page++
      const res = await request({
        url: "/artist/list",
        data: {
          // cat: this.catList[this.areaIndex][this.typeIndex],
          type: this.type[this.typeIndex].id,
          area: this.area[this.areaIndex].id,
          initial: this.letterIndex == 0 ? -1 : this.letter[this.letterIndex],
          offset: (this.page - 1) * this.limit,
        },
        method: "get",
      })
      this.singerList.push(...res.artists)
    },
    // 生成26的字母
    getLetter() {
      for (var i = 0; i < 26; i++) {
        this.letter
        this.letter.push(String.fromCharCode(65 + i))
      }
    },
    gotoSinger(singer) {
      this.$router.push(`/home/index/singer?id=${singer.id}`)
      // uni.navigateTo({
      //   url: "/pages/singer/singer?id=" + singer.id,
      // })
      // // uni.$emit("getsinger",singer)
      // uni.setStorageSync("singer", singer)
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../../../../../static/scss/common.scss";
.singer_square {
  width: 100%;
}
.areabox {
  margin: 10px 20px;
  margin-top: 40px;
  font-size: 14px;
  display: flex;
  .areaitem {
    padding: 5px 0px;
    width: 60px;
    text-align: center;
  }
  .areaitem:not(:last-child) {
    border-right: 1px solid #ccc;
  }
  .areaitem:hover {
    cursor: pointer;
  }
}
.active {
  color: $primary;
  background: $bg;
}
.typebox {
  margin: 10px 20px;
  font-size: 14px;
  display: flex;
  .typeitem {
    padding: 5px 0px;
    width: 60px;
    text-align: center;
  }
  .typeitem:not(:last-child) {
    border-right: 1px solid #ccc;
  }
  .typeitem:hover {
    cursor: pointer;
  }
}
.title {
  font-weight: bold;
  font-size: 16px;
}
.screening {
  display: flex;
  margin: 0px 20px;
  .screening_item {
    width: calc(100% - 50px);
    display: flex;
    flex-wrap: wrap;
    span {
      padding: 5px 0px;
      display: inline-block;
      width: 40px;
      margin-bottom: 10px;
      text-align: center;
    }
    span:nth-child(1) {
      width: 60px;
    }
    span:hover {
      cursor: pointer;
    }
    span:not(:last-child) {
      border-right: 1px solid #ccc;
    }
  }
}
.singerbox {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .singeritem {
    width: 16.666%;
    margin-top: 30px;
    .singerimage {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
      img {
        width: 100%;
        height: auto;
        border-radius: 5px;
      }
    }
    .singername {
      font-size: 14px;
      width: 100%;
      text-align: center;
    }
  }
}
.more {
  width: 100%;
  text-align: center;
  display: block;
  line-height: 1rem;
  padding: 0.9rem 0rem;
  color: rgba(168, 168, 168, 0.8);
}
.more:hover {
  cursor: pointer;
}
</style>
